<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      :visible.sync="visible"
    >
      <el-form
        :model="inputForm"
        ref="inputForm"
        v-loading="loading"
        :class="method === 'view' ? 'readonly' : ''"
        :disabled="method === 'view'"
        label-width="120px"
      >
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="回复内容" prop="replyContent" :rules="[]">
              <el-input
                type="textarea"
                v-model="inputForm.replyContent"
                placeholder="请填写回复内容"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">关闭</el-button>
        <el-button type="primary" @click="doSubmit()" v-noMoreClick
          >回复</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title: "",
      method: "",
      visible: false,
      loading: false,
      inputForm: {
        id: "",
        replyContent: "",
        userId: "",
      },
    };
  },
  components: {},
  methods: {
    init(method, id, userId) {
      this.method = method;
      this.inputForm.id = id;
      this.inputForm.userId = userId;
      this.title = `回复反馈意见`;
      this.visible = true;
    },
    // 表单提交
    doSubmit() {
      // debugger;
      if (!this.inputForm.replyContent) {
        this.$message.error(`请输入回复内容后提交！`);
        return false;
      }
      this.$refs["inputForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$http({
            url: `/commonproblemfeedback/commonProblemFeedback/reply`,
            method: "post",
            data: this.inputForm,
          }).then(({ data }) => {
            this.loading = false;
            if (data && data.success) {
              this.visible = false;
              this.$message.success(data.msg);
              this.inputForm.replyContent = "";
              this.$emit("refreshDataList");
            }
          });
        }
      });
    },
  },
};
</script>
